
function demo(time){
    if(time > 1){
        $("#logic").css("background-color","#ccc");
        time--;
        $("#logic").val(time+"分钟");
        $("#logic").attr("disabled",true);
        setTimeout(function () {
            demo(time);
        },60000);

    }else{
        console.log("恢复按钮");
        $("#logic").css("background-color","#008B8B");
        $("#logic").val("登录");
        $("#logic").attr("disabled",false);
    }
}
function checkIdentify(data,obj){
    if(!data){
        layer.msg("验证码错误");
        $.post(basePath+"user/identifyErrors",obj,function (map) {
            console.log("errorNumber:   "+map.errorNumber);
            if(!map.success){
                var time = Math.floor(map.lastTime/60);
                layer.msg("您还有"+time+"分钟才能再次登录！！！");
                demo(time+1);
                return false;
            }
            if(map.errorNumber == 5){
                layer.msg("您在10分钟内验证码出错5次，30分钟后才能再次登录");
                demo(30);
            }
        });
        return;
    }
    $.post(basePath+"user/logic",obj,function (map) {
        if(null != map.successes){
            if(!map.successes){
                var time = Math.floor(map.lastTime/60);
                layer.msg("您还有"+time+"分钟才能再次登录！！！");
                demo(time+1);
                return ;
            }
        }
        layer.msg(map.message);
        if(map.success){
            var object = map.user;
            //是不是弹窗登录
            var isd=$("#isd").val();
            if(isd==1){//是弹窗登录
                layerClose(500,true);
            }else{
                //重回进入页面
                forwardIntoUrl(1000);
            }

            //window.location.href= basePath+"user/queryPage?id="+object.id;
        }
    })

}


function logic(){
    var email = $("#email").val();
    var password = $("#password").val();
    if(email == "" || email == null){
        layer.msg("邮箱不能为空");
        return false;
    }
    if(password == "" || password == null){
        layer.msg("密码不能为空");
        return false;
    }

    if(password.length < 6 || password.length > 18){
        layer.msg("密码长度不符合要求");
        return false;
    }

    var regex = /^\w{5,}@[a-z0-9]{2,3}\.[a-z]+$|\,$/;
    if(!regex.test(email)){
        layer.msg("邮箱账号不规范");
        return false;
    }
    //判断图片验证码
    var identify = $("#code").val();
    var object = {
        identify:identify
    };
    $.post(basePath+"user/identify",object,function (data) {
        console.log("验证码:   "+data);
        password = MD5(password);
        var obj = {
            email : email,
            password : password,
        };
        checkIdentify(data,obj);
    });

}


$(function () {

    $("#logic").click(logic);

    $("#codeImg").click(function () {
        $("#codeImg").attr("src",basePath+"verifyCode/verify?time="+new Date().getTime());
    });
})